package com.ruoyi.model.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.model.domain.ConstructData;
import com.ruoyi.model.service.IConstructDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 建模数据Controller
 *
 * @author weihanqiang
 * @date 2025-04-18
 */
@RestController
@RequestMapping("/model/construct")
public class ConstructDataController extends BaseController
{
    @Autowired
    private IConstructDataService constructDataService;

    /**
     * 查询建模数据列表
     */
    @PreAuthorize("@ss.hasPermi('model:construct:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConstructData constructData)
    {
        startPage();
        List<ConstructData> list = constructDataService.selectConstructDataList(constructData);
        return getDataTable(list);
    }

    /**
     * 导出建模数据列表
     */
    @PreAuthorize("@ss.hasPermi('model:construct:export')")
    @Log(title = "建模数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ConstructData constructData)
    {
        List<ConstructData> list = constructDataService.selectConstructDataList(constructData);
        ExcelUtil<ConstructData> util = new ExcelUtil<ConstructData>(ConstructData.class);
        util.exportExcel(response, list, "建模数据数据");
    }

    /**
     * 获取建模数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('model:construct:query')")
    @GetMapping(value = "/{constructId}")
    public AjaxResult getInfo(@PathVariable("constructId") Long constructId)
    {
        return success(constructDataService.selectConstructDataByConstructId(constructId));
    }

    /**
     * 新增建模数据
     */
    @PreAuthorize("@ss.hasPermi('model:construct:add')")
    @Log(title = "建模数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConstructData constructData)
    {
        constructData.setCreatorId(getUserId());
        constructData.setCreator(getUsername());
        return toAjax(constructDataService.insertConstructData(constructData));
    }

    /**
     * 修改建模数据
     */
    @PreAuthorize("@ss.hasPermi('model:construct:edit')")
    @Log(title = "建模数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConstructData constructData)
    {
        return toAjax(constructDataService.updateConstructData(constructData));
    }

    /**
     * 删除建模数据
     */
    @PreAuthorize("@ss.hasPermi('model:construct:remove')")
    @Log(title = "建模数据", businessType = BusinessType.DELETE)
    @DeleteMapping("/{constructIds}")
    public AjaxResult remove(@PathVariable Long[] constructIds)
    {
        return toAjax(constructDataService.deleteConstructDataByConstructIds(constructIds));
    }
}
